/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */
#pragma once

#include "PrimitiveAnimation.h"
#include <vector>
#include <xml/Object.h>

namespace liba {
namespace animate {

/** @stereotype container */
template< typename K >
class PrimitiveAnimations : public xml::ObjectANSI
{
public:
	PrimitiveAnimations()
	{}
	void change_position( time_float position )
	{
		typename std::vector< PrimitiveAnimation< K > >::iterator it = primitive_animations.begin();
		for( ; it != primitive_animations.end(); ++it )
		{
			it->change_position( position );
		}
	}
	time_float get_length()const
	{
		time_float ma(0);
		typename std::vector< PrimitiveAnimation< K > >::const_iterator it = primitive_animations.begin();
		for( ; it != primitive_animations.end(); ++it )
			if( it->get_length() > ma )
				ma = it->get_length();
		return ma;
	}
	bool bind( Node * animation_root, bool recursion )
	{
		bool result = true;
		typename std::vector< PrimitiveAnimation< K > >::iterator it = primitive_animations.begin();
		for( ; it != primitive_animations.end(); ++it )
			if( !it->bind( animation_root, recursion ) )
				result = false;
		return result;
	}
protected:
	virtual bool on_node(xml::Provider * prov, const std::string & name )
	{
		if ( name == "PrimitiveAnimation" )
		{
			PrimitiveAnimation< K > pa;
			primitive_animations.push_back( pa );
			return prov->parse_object( &primitive_animations.back() );
		}
		return false;
	}
private:
	std::vector< PrimitiveAnimation< K > > primitive_animations;
};

} // namespace animate
} // namespace liba
using namespace liba;
